import 'package:flutter/material.dart';
import 'package:flutterapp/tab/CateGoryPage.dart';
import 'package:flutterapp/tab/Home.dart';
import 'package:flutterapp/tab/SettingPage.dart';

void main(List<String> args) {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // 去掉debug图标
      debugShowCheckedModeBanner: false,
      title: "Demo",
      theme: ThemeData(
        primarySwatch: Colors.red,
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

// 首先需要在需要Tab组件的混入一下 `SingleTickerProviderStateMixin`类
//混入一下 SingleTickerProviderStateMixin类
class _HomePageState extends State<HomePage> {
  int _currentIndex = 0;
  List _pageList = [Home(), CateGoryPage(), SettingPage()];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // appBar: AppBar(
      //   title: Text('Flutter Demo'),
      // ),
      body: this._pageList[this._currentIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: this._currentIndex, //配置默认选中的菜单，从下标零开始
        onTap: (int index) {
          setState(() {
            //改变状态
            this._currentIndex = index;
          });
        },
        iconSize: 50, //icon大小
        fixedColor: Colors.red, //选中时颜色
        type: BottomNavigationBarType.fixed, //三个以上一定要设置type属性保证正常显示
        items: [
          BottomNavigationBarItem(
            label: '首页',
            icon: Icon(Icons.home),
            tooltip: '首页', //长按显示的文本
          ),
          BottomNavigationBarItem(
            label: '分类',
            icon: Icon(Icons.settings),
            tooltip: '分类',
          ),
          BottomNavigationBarItem(
            label: '设置',
            icon: Icon(Icons.category),
            tooltip: '设置',
          ),
        ],
      ),
    );
  }
}
